package  
{
	import code.InlineFunctoin;
	import code.publicFunction;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.utils.getTimer;
	import xxl.robotlegs.bundles.mvcs.MVCSBundle;
	import xxl.robotlegs.extensions.contextsignal.ContextSignalExtension;
	import xxl.robotlegs.extensions.contextview.ContextViewExtension;
	import xxl.robotlegs.extensions.contextview.impl.ContextView;
	import xxl.robotlegs.extensions.contextview.impl.ContextViewListenerConfig;
	import xxl.robotlegs.extensions.contextview.StageSyncExtension;
	import xxl.robotlegs.extensions.directcommandmap.DirectCommandMapExtension;
	import xxl.robotlegs.extensions.enhancedlogging.InjectableLoggerExtension;
	import xxl.robotlegs.extensions.enhancedlogging.TraceLoggingExtension;
	import xxl.robotlegs.extensions.localsignalmap.LocalSignalMapExtension;
	import xxl.robotlegs.extensions.mediatormap.api.IMediatorMap;
	import xxl.robotlegs.extensions.mediatormap.MediatorMapExtension;
	import xxl.robotlegs.extensions.modularity.ModularityExtension;
	import xxl.robotlegs.extensions.signalcommandmap.SignalCommandMapExtension;
	import xxl.robotlegs.extensions.viewmanager.StageCrawlerExtension;
	import xxl.robotlegs.extensions.viewmanager.StageObserverExtension;
	import xxl.robotlegs.extensions.viewmanager.ViewManagerExtension;
	import xxl.robotlegs.extensions.viewprocessormap.api.IViewProcessorMap;
	import xxl.robotlegs.extensions.viewprocessormap.ViewProcessorMapExtension;
	import xxl.robotlegs.extensions.vigilance.VigilanceExtension;
	import xxl.robotlegs.framework.impl.Context;
	import xxl.robotlegs.framework.impl.log.LogLevel;
	import xxl.signals.api.events.IBubbleEventHandler;
	import xxl.signals.api.events.IEvent;
	import xxl.signals.impl.DeluxeSignal;
	import xxl.signals.impl.LazySignal;
	import xxl.signals.impl.MapSignal;
	import xxl.signals.impl.MonoSignal;
	import xxl.signals.impl.natives.sets.DisplayObjectSignalSet;
	import xxl.signals.impl.OnceSignal;
	import xxl.signals.impl.PrioritySignal;
	import xxl.signals.impl.Signal;
	
	/**
	 * ...
	 * @author XXL
	 */
	public class Main6 extends Sprite implements IBubbleEventHandler
	{
		private var txt:TextField;
		public function Main6() 
		{
			OnceSignal;
			Signal;
			PrioritySignal;
			MonoSignal;
			MapSignal;
			LazySignal;
			DeluxeSignal;
			
			txt = new TextField();
			addChild(txt);
			
			var t:int = getTimer();
			var c:Context = new Context();
			c.install(MVCSBundle);
			c.configure(new ContextView(this));
			
			//var child:Context = new Context();
			//c.addChild(child);
			
			//c.initialize();
			//c.injector.map(Sprite, "abc").toValue(new Sprite());
			
			//var childC:Context = new Context();
			//var childS:Sprite = new Sprite();
			//childC.install(TraceLoggingExtension
				//,InjectableLoggerExtension
				//,ContextViewExtension
				//,ModularityExtension
				//,ViewManagerExtension).configure(new ContextView(childS));
			//addChild(childS);
			//childC.initialize();
			//trace("**********", childC.injector.hasMapping(Sprite, "abc"));
			//childC.ini
			//trace(childC);
			//(c.injector.getInstance(IMediatorMap) as IMediatorMap).map(Sprite).toMediator(Mmm);
			//addChild(new Sprite());
			//addChild(new Shape());
			
			//var vpMap:IViewProcessorMap = c.injector.getInstance(IViewProcessorMap);
			//vpMap.map(SpriteTest).toProcess(this);
			
			//c.injector.instantiateUnmapped(D1);
			
			//c.injector.map(SignalTest).asSingleton();
			//var scm:ISignalCommandMap = c.injector.getInstance(ISignalCommandMap);
			//scm.map(SignalTest).toCommand(D1);
			//
			//(c.injector.getInstance(SignalTest) as Signal).dispatch(100, 200, -100);
			//child.initialize();
			//
			//child.destroy();
			//
			//trace(child);
			txt.text = (getTimer() - t).toString();
			
			//var s1:ContextSignal = new ContextSignal(this, String);
			//var s2:ContextSignal = new ContextSignal(this, String);
			//var relay:ContextSignalRelay = new ContextSignalRelay(s1, s2, ["A", "B"]);
			//relay.start();
			//s2.add(fun3).safelyExecute = false;
			//s1.dispatch("A");
			//s1.dispatch("B");
			//s1.dispatch("C");
			
			//testConcat(1, 2, 3, 4);
			
			//stage.addEventListener(MouseEvent.CLICK, clickHandler);
			
			//var s1:Sprite = new SpriteTest();
			//var s2:Sprite = new Sprite();
			//const disSet:DisplayObjectSignalSet = new DisplayObjectSignalSet(s1, true);
			//disSet.addedToStage.add(addToStageHandler).params = [s1, Sprite];
			//addChild(s1);
		}
		
		public function process(view:Object, type:Class, injector:*):void
		{
			trace(view);
		}
		
		private function addToStageHandler(...args):void 
		{
			trace(args);
		}
		
		private function clickHandler(e:MouseEvent):void 
		{
			var i:int;
			var len:int = 1000000;
			var t:int;
			t = getTimer();
			for (i = 0; i < len; i++)
			{
				publicFunction();
			}
			
			txt.text = (getTimer() - t).toString();
			
			t = getTimer();
			for (i = 0; i < len; i++)
			{
				publicFun2();
			}
			txt.appendText("\n" + (getTimer() - t));
			
			var publicFun3:Function = function():void {
				for (var i:int = 0; i < 100; i++) 
				{
					var result:int = i / 10;
				}
			};
			t = getTimer();
			for (i = 0; i < len; i++)
			{
				publicFun3();
			}
			txt.appendText("\n" + (getTimer() - t));
			
			t = getTimer();
			for (i = 0; i < len; i++)
			{
				InlineFunctoin.PublicFunction();
			}
			txt.appendText("\n" + (getTimer() - t));
		}
		
		public function publicFun2():void
		{
			for (var i:int = 0; i < 100; i++) 
			{
				var result:int = i / 10;
			}
		}
		
		private function testConcat(...args):void
		{
			var arr:Array = [ -1, 0];
			arr = arr.concat(args);
			
			var arr2:Array = [ -1, 0];
			arr2 = arr2.concat.apply(null, args);
			
			trace(1);
		}
		
		private function fff(e:IEvent):void
		{
			trace(e);
		}
		
		/* INTERFACE xxl.signals.core.events.IBubbleEventHandler */
		
		public function get bubbleEventHandlerParent():IBubbleEventHandler 
		{
			return null;
		}
		
		public function onEventBubbled(event:IEvent):Boolean 
		{
			trace(event);
			return true;
		}
		
		//private function abc
		
		private function c():void
		{
			trace("callback", arguments);
		}
		
		private function h1():void
		{
			trace("h1", arguments);
		}
		
		private function h2(msg:Object, fun:Function):void
		{
			trace("h2", arguments);
		}
		
		private function fun(v1:int):void
		{
			trace("fun", arguments);
		}
		
		private function fun3(...args):void
		{
			trace("fun3", args);
		}
		
		private function fun2(...args):void
		{
			trace("fun2", args);
		}
		
		private function fun1(...args):void 
		{
			trace("fun1_", args.length);
		}
		
		private function fun4(a1:*, a2:*, a3:*, a4:*, a5:*, a6:int):void
		{
			trace("fun4", arguments);
			throw new Error("aaaaaaa");
		}
		
	}

}
import xxl.robotlegs.extensions.signalcommandmap.api.ISignalCommandMap;
import xxl.robotlegs.framework.api.IContextSignal;
import xxl.signals.impl.Signal;

class D1
{
	[Inject]
	public var value:int;
	
	[Inject(name = "0")]
	public var v0:int;
	
	[Inject(name = "1")]
	public var v1:int;
	
	[Inject(name = "2")]
	public var v2:int;
	
	[Inject]
	public var scm:ISignalCommandMap;
	
	public function D1(s:IContextSignal)
	{
		//trace(s);
	}
	
	public function execute(a1:int,a2:int,a3:int):void
	{
		trace(this + "execute" + "_" + arguments);
		trace(value, v0, v1, v2);
		trace(scm);
	}
}

import flash.display.Sprite;

class SignalTest extends Signal
{
	public function SignalTest()
	{
		super(int, int, int);
	}
}

class SpriteTest extends Sprite
{
	public function SpriteTest()
	{
		
	}
}

//import xxl.signals.base.DeluxeSignal;
//import xxl.signals.core.events.IBubbleEventHandler;
//import xxl.signals.core.events.IEvent;
//
//class Test extends DeluxeSignal implements IBubbleEventHandler
//{
	//private var _parent:Main6;
	//public function Test(parent:Main6)
	//{
		//_parent = parent;
		//super(
	//}
	//
	//public function get bubbleEventHandlerParent():IBubbleEventHandler 
	//{
		//return _parent;
	//}
	//
	//public function onEventBubbled(event:IEvent):Boolean 
	//{
		//return true;
	//}
//}